<template>
  <div class="">
    <div class="page-filter mb10 fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <ProFilter v-model="filter.pro_id" :get-data="getList" />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button size="small" @click="app.resetFields($refs['filter'].$parent,'filter')">清 空</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="app.loading" class="search-table" :data="list" border 
      :summary-method="getSummaries"
      show-summary
      fit highlight-current-row style="width: 100%;">
      <el-table-column label="序号" align="center" width="56px">
        <template slot-scope="{$index}">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="客户名称" width="180px" prop="ctm_name" />
      <el-table-column label="PO单号" width="190px">
        <template slot-scope="{row}">
          {{ 'PO'+row.id }}
        </template>
      </el-table-column>
      <el-table-column label="项目名称" width="260px" prop="pro_name" />
      <el-table-column label="订单金额" align="right" width="140px">
        <template slot-scope="{row}">
          {{ app.toFix(row.trading_price, 2) }}
        </template>
      </el-table-column>
      <el-table-column label="未开票金额" align="right" width="140px">
        <template slot-scope="{row}">
          {{ app.toFix(app.toFix(row.trading_price, 2) - app.toFix(row.total_money, 2), 2) }}
        </template>
      </el-table-column>
      <el-table-column label="开票累计金额" align="right" width="140px">
        <template slot-scope="{row}">
          {{ app.toFix(row.total_money, 2) }}
        </template>
      </el-table-column>
      <el-table-column label="本次金额" align="right" width="140px">
        <template slot-scope="{row}">
          {{ app.toFix(row.money, 2) }}
        </template>
      </el-table-column>
      <el-table-column label="发票类型" width="160px" prop="type" />
      <el-table-column label="税率" width="160px" prop="rate" />
      <el-table-column label="发票抬头" width="160px" prop="header" />
      <el-table-column label="税号" width="160px" prop="tax_num" />
      <el-table-column label="开户行" width="160px" prop="bank" />
      <el-table-column label="银行账号" width="160px" prop="account" />
      <el-table-column label="联系电话" width="160px" prop="phone" />
      <el-table-column label="地址" width="160px" prop="addr" />
      <el-table-column label="结算" width="80px" align="center" :formatter="formatterState" />
      <el-table-column label="申请人" width="160px" prop="nickname" />
      <el-table-column label="申请日期" align="center" width="140px" prop="apply_time" />
      <el-table-column label="备注" min-width="260px" prop="remark" />
      <el-table-column label="操作" align="center" width="90px" fixed="right">
        <template slot-scope="{row}">
          <el-dropdown>
            <el-button type="primary" size="mini">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :disabled="row.state && row.state === 1"
                @click.native="handleDialog({...row, ...
                {dTitle: '开票', dType: 'edit', dField: dField}})"
              >
              开 票
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    <Cos ref="cos" :info="dialog" />
    <Dialog ref="dialog" :get-data="getList" :info="dialog" />
  </div>
</template>

<script>
import ProFilter from '@/components/ProFilter'
import page from '@/utils/page'
import { invoices } from '@/api/finance/invoice'
import Dialog from './components/invoice-dialog'

export default {
  name: '',
  components: { ProFilter, Dialog },
  extends: page,
  props: {
    reqList: {
      default: invoices,
      type: Function
    }
  },
  data() {
    return {
      price: {},
      dField: ['id', 'company', 'pro_id', 'no_tax', 'tax', 'has_tax', 'num',
        'rate', 'type', 'invoice_time', 'collect_time', 'remark']
    }
  },
  created() {
  },
  methods: {
    formatterState(e) {
      let s = '未开票'
      if (e.state && e.state === 1) s = '已开票'
      return s
    },
    getListAfter(e) {
      this.price = e.summary
    },
    getSummaries() {
      const sums = []
      sums[0] = '合计'
      sums[4] = this.app.toFix(this.price.trading_price, 2)
      sums[5] = this.app.toFix(this.price.trading_price - this.price.total_money, 2)
      sums[6] = this.app.toFix(this.price.total_money, 2)
      sums[7] = this.app.toFix(this.price.money, 2)
      return sums
    }
  }
}
</script>
